﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace WFL.Office.Word
{
    public class TableRow
    {
        private readonly object _lock = new object();

        private WordBorders _borders;
        public WordBorders Borders
        {
            get
            {
                if (_borders == null)
                {
                    lock (_lock) { if (_borders == null) { _borders = new WordBorders(_row.Borders); } }
                }
                return _borders;
            }
        }

        private TableCells _cells;
        public TableCells Cells
        {
            get
            {
                if (_cells == null)
                {
                    lock (_lock) { if (_cells == null) { _cells = new TableCells(_row.Cells) { Table = Table }; } }
                }
                return _cells;
            }
        }

        private WordRange _range;
        public WordRange Range
        {
            get
            {
                if (_range == null)
                {
                    lock (_lock) { if (_range == null) { _range = new WordRange(_row.Range) { Document = Table.Document }; } }
                }
                return _range;
            }
        }

        public float Height
        {
            get { return _row.Height; }
            set { _row.Height = value; }
        }

        public RowHeightRule HeightRule
        {
            get { return (RowHeightRule)_row.HeightRule; }
            set { _row.HeightRule = (WdRowHeightRule)value; }
        }

        public RowAlignment Alignment
        {
            get { return (RowAlignment)_row.Alignment; }
            set { _row.Alignment = (WdRowAlignment)value; }
        }

        internal Row _row
        {
            get;
            private set;
        }

        public WordTable Table
        {
            get;
            internal set;
        }

        internal TableRow(Row row)
        {
            _row = row;
        }

    }
}
